package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.PointFileDao;
import cn.topevery.garden.entity.po.PointFile;
import cn.topevery.garden.entity.query.PointFileQuery;
import cn.topevery.garden.entity.vo.PointFileVO;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 样点 附件表
 *
 * @author code-generate
 * @date 2022-03-16
 */
@Service
public class PointFileLogic extends BaseLogic<PointFile> {
    @Autowired
    PointFileDao pointFileDao;

    @Override
    public BaseEntityDao<PointFile, Integer> getDao() {
        return pointFileDao;
    }


    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<PointFileVO> listPage(PointFileQuery query) {
        return pointFileDao.listPage(query);
    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId, Integer[] ids) {
        pointFileDao.delete(userId, ids);
    }

    /**
     * 根据自增id保存或者更新
     *
     * @param pointFile 实体
     */
    public void saveOrUpdate(String userId, PointFile pointFile) {
        pointFileDao.saveOrUpdate(userId, pointFile);
    }

    /**
     * 根据自定义列值来获取对象
     */
    public PointFile getEntityByColumn(String key, String value) {
        return pointFileDao.getEntityByColumn(key, value);
    }

    public void save(String userId, Integer mainId, List<PointFile> fileList) {
        pointFileDao.deleteByMainId(mainId);
        for (PointFile pointFile : fileList) {
            pointFile.setMainId(mainId);
            pointFileDao.saveOrUpdate(userId, pointFile);
        }
    }

    public List<PointFile> getListByMainId(Integer id) {
        return pointFileDao.getListByMainId(id);
    }

    public void deleteByMainId(Integer[] ids) {
        pointFileDao.deleteByMainIds(ids);
    }

    public List<PointFile> getListByPid(String id) {
        return pointFileDao.getListByPid(id);
    }
}
